package pl.vanta.utils.gui.icons;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.Icon;

/**
 * The "missing icon" is a white box with a black border and a red x. It's used
 * to display something when there are issues loading an icon from an external
 * location.
 * 
 * @author Collin Fagan
 */
public class MissingIcon implements Icon
{
	private int			width;
	private int			height;

	private BasicStroke	stroke	= new BasicStroke(3);

	public MissingIcon(int iconSize)
	{
		this.width = this.height = iconSize;
	}

	public MissingIcon()
	{
		this(32);
	}

	public void paintIcon(Component c, Graphics g, int x, int y)
	{
		Graphics2D g2d = (Graphics2D) g.create();

		g2d.setColor(Color.WHITE);
		g2d.fillRect(x, y, this.width, this.height);

		g2d.setColor(Color.BLACK);
		g2d.drawRect(x, y, this.width, this.height);

		g2d.setColor(Color.RED);

		g2d.setStroke(this.stroke);
		g2d.drawLine(x + 5, y + 5, x + this.width - 5, y + this.height - 5);
		g2d.drawLine(x + 5, y + this.height - 5, x + this.width - 5, y + 5);

		g2d.dispose();
	}

	public int getIconWidth()
	{
		return this.width;
	}

	public int getIconHeight()
	{
		return this.height;
	}
}